# R version 4.0.3 (2020-10-10)
# Platform: x86_64-w64-mingw32/x64 (64-bit)
# Running under: Windows 10 x64 (build 19045)
# 
# Matrix products: default
# 
# locale:
#   [1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252 LC_NUMERIC=C                   
# [5] LC_TIME=German_Germany.1252    
# 
# attached base packages:
#   [1] stats     graphics  grDevices utils     datasets  methods   base     
# 
# other attached packages:
#   [1] foreign_0.8-80   car_3.0-10       carData_3.0-4    broom_0.7.4      MatchIt_4.1.0    stargazer_5.2.2  scales_1.3.0    
# [8] ggh4x_0.2.8      labelled_2.13.0  kableExtra_1.4.0 sandwich_3.0-0   lmtest_0.9-38    zoo_1.8-8        texreg_1.37.5   
# [15] ggeffects_1.0.1  haven_2.5.4      forcats_0.5.1    stringr_1.4.0    dplyr_1.0.3      purrr_0.3.4      readr_1.4.0     
# [22] tidyr_1.1.2      tibble_3.0.5     ggplot2_3.4.4    tidyverse_1.3.0 
# 
# loaded via a namespace (and not attached):
#   [1] fs_1.5.0          lubridate_1.7.9.2 insight_0.19.1    httr_1.4.2        rprojroot_2.0.2   tools_4.0.3       backports_1.2.1  
# [8] R6_2.5.0          sjlabelled_1.2.0  DBI_1.1.1         colorspace_2.0-2  withr_3.0.0       tidyselect_1.1.0  curl_4.3         
# [15] compiler_4.0.3    cli_3.1.1         rvest_0.3.6       xml2_1.3.2        labeling_0.4.2    systemfonts_1.0.4 digest_0.6.27    
# [22] rmarkdown_2.6     svglite_2.1.0     rio_0.5.16        pkgconfig_2.0.3   htmltools_0.5.1   dbplyr_2.1.0      fastmap_1.1.0    
# [29] rlang_1.1.2       readxl_1.3.1      rstudioapi_0.13   shiny_1.6.0       farver_2.0.3      generics_0.1.0    jsonlite_1.7.2   
# [36] zip_2.1.1         magrittr_2.0.1    Rcpp_1.0.12       munsell_0.5.0     abind_1.4-5       lifecycle_1.0.4   stringi_1.5.3    
# [43] yaml_2.2.1        MASS_7.3-53       grid_4.0.3        promises_1.1.1    crayon_1.3.4      miniUI_0.1.1.1    lattice_0.20-41  
# [50] hms_1.0.0         knitr_1.48        pillar_1.4.7      reprex_1.0.0      glue_1.4.2        evaluate_1.0.0    data.table_1.13.6
# [57] modelr_0.1.8      vctrs_0.6.5       httpuv_1.5.5      cellranger_1.1.0  gtable_0.3.0      assertthat_0.2.1  xfun_0.47        
# [64] ggExtra_0.10.0    openxlsx_4.2.3    mime_0.9          xtable_1.8-4      later_1.1.0.1     viridisLite_0.4.0 ellipsis_0.3.2   
# [71] here_1.0.1       

# Load packages
library(ggh4x) 

# Robustness check: PID
robustnesscheck_pid <- TRUE

# Load data
source("ObsStudy_01_00_overview_NZSweden.R")
source("ObsStudy_01_03_Sweden_2010.R")
source("ObsStudy_01_04_Germany_GLES_longterm_online_tracking_2013_2017.R")
source("ObsStudy_01_05_Germany_GLES_pre-election_cross-section_2009_2013.R")
source("ObsStudy_01_06_Germany_GLES_panel_2016_2021_waves_2017.R")
source("ObsStudy_01_07_Germany_GLES_2021.R")
source("ObsStudy_01_08_Austria_AUTNES_pre_post_panel_2013.R")
source("ObsStudy_01_09_Austria_AUTNES_Rolling_Cross_Section_Panel_2013.R")
source("ObsStudy_01_10_Austria_AUTNES_Multi_Mode_Panel_2017.R")
source("ObsStudy_01_11_Austria_AUTNES_Online_Panel_2017_2019.R")
source("ObsStudy_01_12_Netherlands_2006.R")
source("ObsStudy_01_13_Belgium_2014.R")
source("ObsStudy_01_14_Spain_2016.R")

overview <- data.frame(Country = character(),
                       Year = numeric(),
                       Study = character(),
                       Party = character(),
                       Variance_Estimate = numeric(),
                       Variance_SE = numeric(),
                       Mean_Estimate = numeric(),
                       Mean_SE = numeric(),
                       LPM = numeric(),
                       stringsAsFactors = FALSE)

overview[nrow(overview)+1,] <- c("NZL",
                                 2020,
                                 "Own Survey",
                                 "LP",
                                 NZ_2020_OS_Labour_Variance_Estimate,
                                 NZ_2020_OS_Labour_Variance_SE,
                                 NZ_2020_OS_Labour_Mean_Estimate,
                                 NZ_2020_OS_Labour_Mean_SE,
                                 0)

overview[nrow(overview)+1,] <- c("SWE",
                                 2018,
                                 "Own Survey",
                                 "S",
                                 SE_2018_OS_SAP_Variance_Estimate,
                                 SE_2018_OS_SAP_Variance_SE,
                                 SE_2018_OS_SAP_Mean_Estimate,
                                 SE_2018_OS_SAP_Mean_SE,
                                 0)

overview[nrow(overview)+1,] <- c("SWE",
                                 2018,
                                 "Own Survey",
                                 "M",
                                 SE_2018_OS_M_Variance_Estimate,
                                 SE_2018_OS_M_Variance_SE,
                                 SE_2018_OS_M_Mean_Estimate,
                                 SE_2018_OS_M_Mean_SE,
                                 0)

overview[nrow(overview)+1,] <- c("SWE",
                                 2010,
                                 "SNES",
                                 "M",
                                 SE_2010_ICP_M_Variance_Estimate,
                                 SE_2010_ICP_M_Variance_SE,
                                 SE_2010_ICP_M_Mean_Estimate,
                                 SE_2010_ICP_M_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("SWE",
                                 2010,
                                 "SNES",
                                 "L",
                                 SE_2010_ICP_FP_Variance_Estimate,
                                 SE_2010_ICP_FP_Variance_SE,
                                 SE_2010_ICP_FP_Mean_Estimate,
                                 SE_2010_ICP_FP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("SWE",
                                 2010,
                                 "SNES",
                                 "CP",
                                 SE_2010_ICP_C_Variance_Estimate,
                                 SE_2010_ICP_C_Variance_SE,
                                 SE_2010_ICP_C_Mean_Estimate,
                                 SE_2010_ICP_C_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("SWE",
                                 2010,
                                 "SNES",
                                 "KD",
                                 SE_2010_ICP_KD_Variance_Estimate,
                                 SE_2010_ICP_KD_Variance_SE,
                                 SE_2010_ICP_KD_Mean_Estimate,
                                 SE_2010_ICP_KD_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("SWE",
                                 2010,
                                 "SNES",
                                 "S",
                                 SE_2010_ICP_S_Variance_Estimate,
                                 SE_2010_ICP_S_Variance_SE,
                                 SE_2010_ICP_S_Mean_Estimate,
                                 SE_2010_ICP_S_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("SWE",
                                 2010,
                                 "SNES",
                                 "MP",
                                 SE_2010_ICP_MP_Variance_Estimate,
                                 SE_2010_ICP_MP_Variance_SE,
                                 SE_2010_ICP_MP_Mean_Estimate,
                                 SE_2010_ICP_MP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("SWE",
                                 2010,
                                 "SNES",
                                 "VSKP",
                                 SE_2010_ICP_V_Variance_Estimate,
                                 SE_2010_ICP_V_Variance_SE,
                                 SE_2010_ICP_V_Mean_Estimate,
                                 SE_2010_ICP_V_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2017,
                                 "GLES Longterm-Online-Tracking",
                                 "CDU/CSU",
                                 GER_2017_GLESLOT_UNION_Variance_Estimate,
                                 GER_2017_GLESLOT_UNION_Variance_SE,
                                 GER_2017_GLESLOT_UNION_Mean_Estimate,
                                 GER_2017_GLESLOT_UNION_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2017,
                                 "GLES Longterm-Online-Tracking",
                                 "SPD",
                                 GER_2017_GLESLOT_SPD_Variance_Estimate,
                                 GER_2017_GLESLOT_SPD_Variance_SE,
                                 GER_2017_GLESLOT_SPD_Mean_Estimate,
                                 GER_2017_GLESLOT_SPD_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2017,
                                 "GLES Longterm-Online-Tracking",
                                 "FDP",
                                 GER_2017_GLESLOT_FDP_Variance_Estimate,
                                 GER_2017_GLESLOT_FDP_Variance_SE,
                                 GER_2017_GLESLOT_FDP_Mean_Estimate,
                                 GER_2017_GLESLOT_FDP_Mean_SE,
                                 1)
 
overview[nrow(overview)+1,] <- c("GER",
                                 2017,
                                 "GLES Longterm-Online-Tracking",
                                 "BGr",
                                 GER_2017_GLESLOT_GR_Variance_Estimate,
                                 GER_2017_GLESLOT_GR_Variance_SE,
                                 GER_2017_GLESLOT_GR_Mean_Estimate,
                                 GER_2017_GLESLOT_GR_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2013,
                                 "GLES Longterm-Online-Tracking",
                                 "CDU/CSU",
                                 GER_2013_GLESLOT_UNION_Variance_Estimate,
                                 GER_2013_GLESLOT_UNION_Variance_SE,
                                 GER_2013_GLESLOT_UNION_Mean_Estimate,
                                 GER_2013_GLESLOT_UNION_Mean_SE,
                                 1)
 
overview[nrow(overview)+1,] <- c("GER",
                                 2013,
                                 "GLES Longterm-Online-Tracking",
                                 "SPD",
                                 GER_2013_GLESLOT_SPD_Variance_Estimate,
                                 GER_2013_GLESLOT_SPD_Variance_SE,
                                 GER_2013_GLESLOT_SPD_Mean_Estimate,
                                 GER_2013_GLESLOT_SPD_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2013,
                                 "GLES Longterm-Online-Tracking",
                                 "FDP",
                                 GER_2013_GLESLOT_FDP_Variance_Estimate,
                                 GER_2013_GLESLOT_FDP_Variance_SE,
                                 GER_2013_GLESLOT_FDP_Mean_Estimate,
                                 GER_2013_GLESLOT_FDP_Mean_SE,
                                 1)
 
overview[nrow(overview)+1,] <- c("GER",
                                 2013,
                                 "GLES Longterm-Online-Tracking",
                                 "BGr",
                                 GER_2013_GLESLOT_GR_Variance_Estimate,
                                 GER_2013_GLESLOT_GR_Variance_SE,
                                 GER_2013_GLESLOT_GR_Mean_Estimate,
                                 GER_2013_GLESLOT_GR_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2013,
                                 "GLES Cross Section (Pre-Election)",
                                 "CDU/CSU",
                                 GER_2013_PECS_UNION_Variance_Estimate,
                                 GER_2013_PECS_UNION_Variance_SE,
                                 GER_2013_PECS_UNION_Mean_Estimate,
                                 GER_2013_PECS_UNION_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2013,
                                 "GLES Cross Section (Pre-Election)",
                                 "SPD",
                                 GER_2013_PECS_SPD_Variance_Estimate,
                                 GER_2013_PECS_SPD_Variance_SE,
                                 GER_2013_PECS_SPD_Mean_Estimate,
                                 GER_2013_PECS_SPD_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2013,
                                 "GLES Cross Section (Pre-Election)",
                                 "FDP",
                                 GER_2013_PECS_FDP_Variance_Estimate,
                                 GER_2013_PECS_FDP_Variance_SE,
                                 GER_2013_PECS_FDP_Mean_Estimate,
                                 GER_2013_PECS_FDP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2013,
                                 "GLES Cross Section (Pre-Election)",
                                 "BGr",
                                 GER_2013_PECS_GR_Variance_Estimate,
                                 GER_2013_PECS_GR_Variance_SE,
                                 GER_2013_PECS_GR_Mean_Estimate,
                                 GER_2013_PECS_GR_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2009,
                                 "GLES Cross Section (Pre-Election)",
                                 "CDU/CSU",
                                 GER_2009_PECS_UNION_Variance_Estimate,
                                 GER_2009_PECS_UNION_Variance_SE,
                                 GER_2009_PECS_UNION_Mean_Estimate,
                                 GER_2009_PECS_UNION_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2009,
                                 "GLES Cross Section (Pre-Election)",
                                 "SPD",
                                 GER_2009_PECS_SPD_Variance_Estimate,
                                 GER_2009_PECS_SPD_Variance_SE,
                                 GER_2009_PECS_SPD_Mean_Estimate,
                                 GER_2009_PECS_SPD_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2009,
                                 "GLES Cross Section (Pre-Election)",
                                 "FDP",
                                 GER_2009_PECS_FDP_Variance_Estimate,
                                 GER_2009_PECS_FDP_Variance_SE,
                                 GER_2009_PECS_FDP_Mean_Estimate,
                                 GER_2009_PECS_FDP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2009,
                                 "GLES Cross Section (Pre-Election)",
                                 "BGr",
                                 GER_2009_PECS_GR_Variance_Estimate,
                                 GER_2009_PECS_GR_Variance_SE,
                                 GER_2009_PECS_GR_Mean_Estimate,
                                 GER_2009_PECS_GR_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2017,
                                 "GLES Panel 2016-2021 (Wave 7)",
                                 "CDU/CSU",
                                 GER_2017_GLES_Panel_w7_UNION_Variance_Estimate,
                                 GER_2017_GLES_Panel_w7_UNION_Variance_SE,
                                 GER_2017_GLES_Panel_w7_UNION_Mean_Estimate,
                                 GER_2017_GLES_Panel_w7_UNION_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2017,
                                 "GLES Panel 2016-2021 (Wave 7)",
                                 "SPD",
                                 GER_2017_GLES_Panel_w7_SPD_Variance_Estimate,
                                 GER_2017_GLES_Panel_w7_SPD_Variance_SE,
                                 GER_2017_GLES_Panel_w7_SPD_Mean_Estimate,
                                 GER_2017_GLES_Panel_w7_SPD_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2017,
                                 "GLES Panel 2016-2021 (Wave 7)",
                                 "FDP",
                                 GER_2017_GLES_Panel_w7_FDP_Variance_Estimate,
                                 GER_2017_GLES_Panel_w7_FDP_Variance_SE,
                                 GER_2017_GLES_Panel_w7_FDP_Mean_Estimate,
                                 GER_2017_GLES_Panel_w7_FDP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2017,
                                 "GLES Panel 2016-2021 (Wave 7)",
                                 "BGr",
                                 GER_2017_GLES_Panel_w7_GR_Variance_Estimate,
                                 GER_2017_GLES_Panel_w7_GR_Variance_SE,
                                 GER_2017_GLES_Panel_w7_GR_Mean_Estimate,
                                 GER_2017_GLES_Panel_w7_GR_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2021,
                                 "GLES Panel 2016-2021 (Wave 17)",
                                 "CDU/CSU",
                                 GER_2021_GLES_Panel_w17_UNION_Variance_Estimate,
                                 GER_2021_GLES_Panel_w17_UNION_Variance_SE,
                                 GER_2021_GLES_Panel_w17_UNION_Mean_Estimate,
                                 GER_2021_GLES_Panel_w17_UNION_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2021,
                                 "GLES Panel 2016-2021 (Wave 17)",
                                 "SPD",
                                 GER_2021_GLES_Panel_w17_SPD_Variance_Estimate,
                                 GER_2021_GLES_Panel_w17_SPD_Variance_SE,
                                 GER_2021_GLES_Panel_w17_SPD_Mean_Estimate,
                                 GER_2021_GLES_Panel_w17_SPD_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2021,
                                 "GLES Panel 2016-2021 (Wave 17)",
                                 "FDP",
                                 GER_2021_GLES_Panel_w17_FDP_Variance_Estimate,
                                 GER_2021_GLES_Panel_w17_FDP_Variance_SE,
                                 GER_2021_GLES_Panel_w17_FDP_Mean_Estimate,
                                 GER_2021_GLES_Panel_w17_FDP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("GER",
                                 2021,
                                 "GLES Panel 2016-2021 (Wave 17)",
                                 "BGr",
                                 GER_2021_GLES_Panel_w17_GR_Variance_Estimate,
                                 GER_2021_GLES_Panel_w17_GR_Variance_SE,
                                 GER_2021_GLES_Panel_w17_GR_Mean_Estimate,
                                 GER_2021_GLES_Panel_w17_GR_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2013,
                                 "AUTNES Pre-Panel",
                                 "SPÖ",
                                 AUT_2013_AUTNES_Pre_Panel_SPO_Variance_Estimate,
                                 AUT_2013_AUTNES_Pre_Panel_SPO_Variance_SE,
                                 AUT_2013_AUTNES_Pre_Panel_SPO_Mean_Estimate,
                                 AUT_2013_AUTNES_Pre_Panel_SPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2013,
                                 "AUTNES Pre-Panel",
                                 "ÖVP",
                                 AUT_2013_AUTNES_Pre_Panel_OVP_Variance_Estimate,
                                 AUT_2013_AUTNES_Pre_Panel_OVP_Variance_SE,
                                 AUT_2013_AUTNES_Pre_Panel_OVP_Mean_Estimate,
                                 AUT_2013_AUTNES_Pre_Panel_OVP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2013,
                                 "AUTNES Pre-Panel",
                                 "FPÖ",
                                 AUT_2013_AUTNES_Pre_Panel_FPO_Variance_Estimate,
                                 AUT_2013_AUTNES_Pre_Panel_FPO_Variance_SE,
                                 AUT_2013_AUTNES_Pre_Panel_FPO_Mean_Estimate,
                                 AUT_2013_AUTNES_Pre_Panel_FPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2013,
                                 "AUTNES Rolling Cross Section Panel",
                                 "SPÖ",
                                 AUT_2013_AUTNES_RCSP_SPO_Variance_Estimate,
                                 AUT_2013_AUTNES_RCSP_SPO_Variance_SE,
                                 AUT_2013_AUTNES_RCSP_SPO_Mean_Estimate,
                                 AUT_2013_AUTNES_RCSP_SPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2013,
                                 "AUTNES Rolling Cross Section Panel",
                                 "ÖVP",
                                 AUT_2013_AUTNES_RCSP_OVP_Variance_Estimate,
                                 AUT_2013_AUTNES_RCSP_OVP_Variance_SE,
                                 AUT_2013_AUTNES_RCSP_OVP_Mean_Estimate,
                                 AUT_2013_AUTNES_RCSP_OVP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2013,
                                 "AUTNES Rolling Cross Section Panel",
                                 "FPÖ",
                                 AUT_2013_AUTNES_RCSP_FPO_Variance_Estimate,
                                 AUT_2013_AUTNES_RCSP_FPO_Variance_SE,
                                 AUT_2013_AUTNES_RCSP_FPO_Mean_Estimate,
                                 AUT_2013_AUTNES_RCSP_FPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2017,
                                 "AUTNES Multi-Mode Panel",
                                 "SPÖ",
                                 AUT_2017_AUTNES_MMP_SPO_Variance_Estimate,
                                 AUT_2017_AUTNES_MMP_SPO_Variance_SE,
                                 AUT_2017_AUTNES_MMP_SPO_Mean_Estimate,
                                 AUT_2017_AUTNES_MMP_SPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2017,
                                 "AUTNES Multi-Mode Panel",
                                 "ÖVP",
                                 AUT_2017_AUTNES_MMP_OVP_Variance_Estimate,
                                 AUT_2017_AUTNES_MMP_OVP_Variance_SE,
                                 AUT_2017_AUTNES_MMP_OVP_Mean_Estimate,
                                 AUT_2017_AUTNES_MMP_OVP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2017,
                                 "AUTNES Multi-Mode Panel",
                                 "FPÖ",
                                 AUT_2017_AUTNES_MMP_FPO_Variance_Estimate,
                                 AUT_2017_AUTNES_MMP_FPO_Variance_SE,
                                 AUT_2017_AUTNES_MMP_FPO_Mean_Estimate,
                                 AUT_2017_AUTNES_MMP_FPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2017,
                                 "AUTNES Online Panel (Wave 4)",
                                 "SPÖ",
                                 AUT_2017_AUTNES_OP_w4_SPO_Variance_Estimate,
                                 AUT_2017_AUTNES_OP_w4_SPO_Variance_SE,
                                 AUT_2017_AUTNES_OP_w4_SPO_Mean_Estimate,
                                 AUT_2017_AUTNES_OP_w4_SPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2017,
                                 "AUTNES Online Panel (Wave 4)",
                                 "ÖVP",
                                 AUT_2017_AUTNES_OP_w4_OVP_Variance_Estimate,
                                 AUT_2017_AUTNES_OP_w4_OVP_Variance_SE,
                                 AUT_2017_AUTNES_OP_w4_OVP_Mean_Estimate,
                                 AUT_2017_AUTNES_OP_w4_OVP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2017,
                                 "AUTNES Online Panel (Wave 4)",
                                 "FPÖ",
                                 AUT_2017_AUTNES_OP_w4_FPO_Variance_Estimate,
                                 AUT_2017_AUTNES_OP_w4_FPO_Variance_SE,
                                 AUT_2017_AUTNES_OP_w4_FPO_Mean_Estimate,
                                 AUT_2017_AUTNES_OP_w4_FPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2019,
                                 "AUTNES Online Panel (Wave 11)",
                                 "SPÖ",
                                 AUT_2019_AUTNES_OP_w11_SPO_Variance_Estimate,
                                 AUT_2019_AUTNES_OP_w11_SPO_Variance_SE,
                                 AUT_2019_AUTNES_OP_w11_SPO_Mean_Estimate,
                                 AUT_2019_AUTNES_OP_w11_SPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2019,
                                 "AUTNES Online Panel (Wave 11)",
                                 "ÖVP",
                                 AUT_2019_AUTNES_OP_w11_OVP_Variance_Estimate,
                                 AUT_2019_AUTNES_OP_w11_OVP_Variance_SE,
                                 AUT_2019_AUTNES_OP_w11_OVP_Mean_Estimate,
                                 AUT_2019_AUTNES_OP_w11_OVP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("AUT",
                                 2019,
                                 "AUTNES Online Panel (Wave 11)",
                                 "FPÖ",
                                 AUT_2019_AUTNES_OP_w11_FPO_Variance_Estimate,
                                 AUT_2019_AUTNES_OP_w11_FPO_Variance_SE,
                                 AUT_2019_AUTNES_OP_w11_FPO_Mean_Estimate,
                                 AUT_2019_AUTNES_OP_w11_FPO_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("NED",
                                 2006,
                                 "DPES",
                                 "PvdA",
                                 NED_2006_PES_PvdA_Variance_Estimate,
                                 NED_2006_PES_PvdA_Variance_SE,
                                 NED_2006_PES_PvdA_Mean_Estimate,
                                 NED_2006_PES_PvdA_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("NED",
                                 2006,
                                 "DPES",
                                 "CDA",
                                 NED_2006_PES_CDA_Variance_Estimate,
                                 NED_2006_PES_CDA_Variance_SE,
                                 NED_2006_PES_CDA_Mean_Estimate,
                                 NED_2006_PES_CDA_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("NED",
                                 2006,
                                 "DPES",
                                 "VVD",
                                 NED_2006_PES_VVD_Variance_Estimate,
                                 NED_2006_PES_VVD_Variance_SE,
                                 NED_2006_PES_VVD_Mean_Estimate,
                                 NED_2006_PES_VVD_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("BEL",
                                 2014,
                                 "BNES",
                                 "PS",
                                 BEL_2014_BNES_PS_Variance_Estimate,
                                 BEL_2014_BNES_PS_Variance_SE,
                                 BEL_2014_BNES_PS_Mean_Estimate,
                                 BEL_2014_BNES_PS_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("BEL",
                                 2014,
                                 "BNES",
                                 "SPA",
                                 BEL_2014_BNES_SP.A_Variance_Estimate,
                                 BEL_2014_BNES_SP.A_Variance_SE,
                                 BEL_2014_BNES_SP.A_Mean_Estimate,
                                 BEL_2014_BNES_SP.A_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("BEL",
                                 2014,
                                 "BNES",
                                 "CDV",
                                 BEL_2014_BNES_CDV_Variance_Estimate,
                                 BEL_2014_BNES_CDV_Variance_SE,
                                 BEL_2014_BNES_CDV_Mean_Estimate,
                                 BEL_2014_BNES_CDV_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("BEL",
                                 2014,
                                 "BNES",
                                 "CDH",
                                 BEL_2014_BNES_CDH_Variance_Estimate,
                                 BEL_2014_BNES_CDH_Variance_SE,
                                 BEL_2014_BNES_CDH_Mean_Estimate,
                                 BEL_2014_BNES_CDH_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("BEL",
                                 2014,
                                 "BNES",
                                 "MR",
                                 BEL_2014_BNES_MR_Variance_Estimate,
                                 BEL_2014_BNES_MR_Variance_SE,
                                 BEL_2014_BNES_MR_Mean_Estimate,
                                 BEL_2014_BNES_MR_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("BEL",
                                 2014,
                                 "BNES",
                                 "OVLD",
                                 BEL_2014_BNES_OpenVLD_Variance_Estimate,
                                 BEL_2014_BNES_OpenVLD_Variance_SE,
                                 BEL_2014_BNES_OpenVLD_Mean_Estimate,
                                 BEL_2014_BNES_OpenVLD_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("BEL",
                                 2014,
                                 "BNES",
                                 "Ecolo",
                                 BEL_2014_BNES_Ecolo_Variance_Estimate,
                                 BEL_2014_BNES_Ecolo_Variance_SE,
                                 BEL_2014_BNES_Ecolo_Mean_Estimate,
                                 BEL_2014_BNES_Ecolo_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("BEL",
                                 2014,
                                 "BNES",
                                 "Gr",
                                 BEL_2014_BNES_Groen_Variance_Estimate,
                                 BEL_2014_BNES_Groen_Variance_SE,
                                 BEL_2014_BNES_Groen_Mean_Estimate,
                                 BEL_2014_BNES_Groen_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("ESP",
                                 2016,
                                 "ESPNES",
                                 "PP",
                                 ESP_2016_SNES_PP_Variance_Estimate,
                                 ESP_2016_SNES_PP_Variance_SE,
                                 ESP_2016_SNES_PP_Mean_Estimate,
                                 ESP_2016_SNES_PP_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("ESP",
                                 2016,
                                 "ESPNES",
                                 "PSOE",
                                 ESP_2016_SNES_PSOE_Variance_Estimate,
                                 ESP_2016_SNES_PSOE_Variance_SE,
                                 ESP_2016_SNES_PSOE_Mean_Estimate,
                                 ESP_2016_SNES_PSOE_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("ESP",
                                 2016,
                                 "ESPNES",
                                 "PODEMOS",
                                 ESP_2016_SNES_Podemos_Variance_Estimate,
                                 ESP_2016_SNES_Podemos_Variance_SE,
                                 ESP_2016_SNES_Podemos_Mean_Estimate,
                                 ESP_2016_SNES_Podemos_Mean_SE,
                                 1)

overview[nrow(overview)+1,] <- c("ESP",
                                 2016,
                                 "ESPNES",
                                 "C",
                                 ESP_2016_SNES_Ciudadanos_Variance_Estimate,
                                 ESP_2016_SNES_Ciudadanos_Variance_SE,
                                 ESP_2016_SNES_Ciudadanos_Mean_Estimate,
                                 ESP_2016_SNES_Ciudadanos_Mean_SE,
                                 1)

av_variance_estimate_lpm1 <- sum(overview$Variance_Estimate[overview$LPM==1]*(1/overview$Variance_SE[overview$LPM==1]^2))/sum((1/overview$Variance_SE[overview$LPM==1]^2))
av_variance_se_lpm1 <- sqrt(1/sum((1/overview$Variance_SE[overview$LPM==1]^2)))
av_variance_conf_low_lpm1 <- av_variance_estimate_lpm1 - qnorm(0.975) * av_variance_se_lpm1
av_variance_conf_high_lpm1 <- av_variance_estimate_lpm1 + qnorm(0.975) * av_variance_se_lpm1

av_variance_estimate_lpm0 <- sum(overview$Variance_Estimate[overview$LPM==0]*(1/overview$Variance_SE[overview$LPM==0]^2))/sum((1/overview$Variance_SE[overview$LPM==0]^2))
av_variance_se_lpm0 <- sqrt(1/sum((1/overview$Variance_SE[overview$LPM==0]^2)))
av_variance_conf_low_lpm0 <- av_variance_estimate_lpm0 - qnorm(0.975) * av_variance_se_lpm0
av_variance_conf_high_lpm0 <- av_variance_estimate_lpm0 + qnorm(0.975) * av_variance_se_lpm0

length(overview$Mean_Estimate[overview$LPM==0])
av_mean_estimate_lpm1 <- sum(overview$Mean_Estimate[overview$LPM==1]*(1/overview$Mean_SE[overview$LPM==1]^2))/sum((1/overview$Mean_SE[overview$LPM==1]^2))
av_mean_se_lpm1 <- sqrt(1/sum((1/overview$Mean_SE[overview$LPM==1]^2)))
av_mean_conf_low_lpm1 <- av_mean_estimate_lpm1 - qnorm(0.975) * av_mean_se_lpm1
av_mean_conf_high_lpm1 <- av_mean_estimate_lpm1 + qnorm(0.975) * av_mean_se_lpm1

av_mean_estimate_lpm0 <- sum(overview$Mean_Estimate[overview$LPM==0]*(1/overview$Mean_SE[overview$LPM==0]^2))/sum((1/overview$Mean_SE[overview$LPM==0]^2))
av_mean_se_lpm0 <- sqrt(1/sum((1/overview$Mean_SE[overview$LPM==0]^2)))
av_mean_conf_low_lpm0 <- av_mean_estimate_lpm0 - qnorm(0.975) * av_mean_se_lpm0
av_mean_conf_high_lpm0 <- av_mean_estimate_lpm0 + qnorm(0.975) * av_mean_se_lpm0

overview[nrow(overview)+1,] <- c("Combined",
                                 "",
                                 "DV: vote choice (yes/no)",
                                 "",
                                 av_variance_estimate_lpm1,
                                 av_variance_se_lpm1,
                                 av_mean_estimate_lpm1,
                                 av_mean_se_lpm1,
                                 1)

overview[nrow(overview)+1,] <- c("Combined",
                                 "",
                                 "DV: propensitiy to vote",
                                 "",
                                 av_variance_estimate_lpm0,
                                 av_variance_se_lpm0,
                                 av_mean_estimate_lpm0,
                                 av_mean_se_lpm0,
                                 0)

overview$Country <- factor(overview$Country, levels=c("AUT", "BEL", "ESP", "GER", "NED", "NZL", "SWE", "Combined"))
overview$Year <- as.character(overview$Year)
overview$Study <- as.character(overview$Study)
overview$Party <- as.character(overview$Party)
overview$Variance_Estimate <- as.numeric(overview$Variance_Estimate)
overview$Variance_SE <- as.numeric(overview$Variance_SE)
overview$Mean_Estimate <- as.numeric(overview$Mean_Estimate)
overview$Mean_SE <- as.numeric(overview$Mean_SE)
overview$LPM <- as.numeric(overview$LPM)



overview <- overview %>% mutate(conf_low_variance = Variance_Estimate - qnorm(0.975) * Variance_SE, 
                                conf_high_variance = Variance_Estimate + qnorm(0.975) * Variance_SE,
                                conf_low_mean = Mean_Estimate - qnorm(0.975) * Mean_SE, 
                                conf_high_mean = Mean_Estimate + qnorm(0.975) * Mean_SE,
                                pval_variance = pnorm(abs(Variance_Estimate/Variance_SE),lower.tail = F)*2,
                                pval_mean = pnorm(abs(Mean_Estimate/Mean_SE),lower.tail = F)*2,
                                group = paste(Party, Study, Country, sep = ""),
                                sig_variance = ifelse(pval_variance<0.05,1,0),
                                sig_mean = ifelse(pval_mean<0.05,1,0))


overview$hline <- NA
overview$hline[overview$Country=="Combined"] <- 1.6

if (robustnesscheck_pid==FALSE) {
  
  # Figure SM2
  dodge <- position_dodge(0.9)
  ggplot(overview, aes(group = Study, label = Study)) +
    geom_point(aes(x = Variance_Estimate, y= Party, shape = as.factor(LPM), alpha = as.factor(sig_variance)),
               position=dodge) +
    geom_errorbar(aes(x = Variance_Estimate, y= Party, xmin = conf_low_variance, xmax = conf_high_variance, alpha = as.factor(sig_variance)),
                  position=dodge, width=0) +
    geom_vline(aes(xintercept=0), linetype = "dashed", color = "red") +
    geom_text(aes(x = conf_high_variance, y= Party), hjust = -0.2, position = dodge, size = 2) +
    facet_nested(Country+Year~., scales = "free", space = "free") +
    theme_classic() +
    theme(legend.position="bottom") +
    labs(x = "Marginal Effect of Government Lottery Variance",
         y = "Party",
         shape = "") +
    scale_shape_manual(label= c("0" = "DV: propensitiy to vote", "1" = "DV: vote choice (yes/no)"),
                       values= c("0" = 15, "1" = 18)) +
    scale_alpha_discrete(range=c(0.25, 1)) +
    guides(alpha = "none") +
    force_panelsizes(rows = c(6,6,3,8,4,4,8,8,4,3,3,7,3,4)) +
    xlim(c(-1.25,1.75)) +
    geom_hline(data = overview, aes(yintercept = hline))
  ggsave("FigureSM2.pdf", width = 10, height = 15)
  
  # Figure 3
  ggplot(overview[which(overview$Country=="Combined"),], aes(group = Study, label = Study)) +
    geom_point(aes(x = Variance_Estimate, y= Party, shape = as.factor(LPM)),
               position=dodge) +
    geom_errorbar(aes(x = Variance_Estimate, y= Party, xmin = conf_low_variance, xmax = conf_high_variance),
                  position=dodge, size=1, width=0) +
    geom_vline(aes(xintercept=0), linetype = "dashed", color = "red") +
    geom_text(aes(x = Variance_Estimate, y= Party), vjust = 2, position = dodge, size = 3) +
    theme_bw() +
    theme(legend.position="none",
          text = element_text(family = "serif"),
          axis.ticks = element_blank()) +
    labs(x = "Marginal Effect of Government Lottery Variance",
         y = "",
         shape = "") +
    scale_shape_manual(label= c("0" = "DV: propensitiy to vote", "1" = "DV: vote choice (yes/no)"),
                       values= c("0" = 15, "1" = 18)) +
    scale_alpha_discrete(range=c(0.25, 1)) +
    guides(alpha = "none") +
    force_panelsizes(rows = c(6,6,3,8,4,4,8,8,4,3,3,7,3,4)) +
    xlim(c(-0.3,0.05)) +
    geom_hline(data = overview, aes(yintercept = hline))
  ggsave("Figure3.pdf", width = 6, height = 3)
  
  #Table SM17
  print(filter(overview, Country=="Combined")[c("Study", "Variance_Estimate", "Variance_SE", "pval_variance")]) # Estimates and standard errors
    print(sum(overview$LPM[overview$Country!="Combined"]==1)) # Number of studies with vote choice
    print(sum(overview$LPM[overview$Country!="Combined"]==0)) # Number of studies with propensity to vote
} else {
  
  #Figure SM3
    dodge <- position_dodge(0.9)
    ggplot(overview[which(overview$LPM!=0),], aes(group = Study, label = Study)) +
      geom_point(aes(x = Variance_Estimate, y= Party, shape = as.factor(LPM), alpha = as.factor(sig_variance)),
                 position=dodge) +
      geom_errorbar(aes(x = Variance_Estimate, y= Party, xmin = conf_low_variance, xmax = conf_high_variance, alpha = as.factor(sig_variance)),
                    position=dodge, width=0) +
      geom_vline(aes(xintercept=0), linetype = "dashed", color = "red") +
      geom_text(aes(x = conf_high_variance, y= Party), hjust = -0.2, position = dodge, size = 2) +
      facet_nested(Country+Year~., scales = "free", space = "free") +
      theme_classic() +
      theme(legend.position="bottom") +
      labs(x = "Marginal Effect of Government Lottery Variance",
           y = "Party",
           shape = "") +
      scale_shape_manual(label= c("0" = "DV: propensitiy to vote", "1" = "DV: vote choice (yes/no)"),
                         values= c("0" = 15, "1" = 18)) +
      scale_alpha_discrete(range=c(0.25, 1)) +
      guides(alpha = "none") +
      force_panelsizes(rows = c(6,6,3,8,4,4,8,8,4,3,5,4)) +
      xlim(c(-1.25,1.75)) +
      geom_hline(data = overview[which(overview$LPM!=0),], aes(yintercept = hline))
    ggsave("FigureSM3.pdf", width = 10, height = 15)
    
  #Table SM18
    print(filter(overview, Country=="Combined" & Study=="DV: vote choice (yes/no)")[c("Study", "Variance_Estimate", "Variance_SE", "pval_variance")]) # Estimates and standard errors
    print(sum(overview$LPM[overview$Country!="Combined"]==1)) # Number of studies with vote choice
}
